<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<%
xls_id=request("xls_id")
xls_date=request("xls_date")
title=year(xls_date)&"年"&month(xls_date)&"月份电话分摊表"
Response.ContentType = "application/vnd.ms-word"
Response.AddHeader "content-disposition", "inline; filename = "&title&".doc"
%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CC的办公系统</title>
<style type="text/css">
/*
Copyright (c) 2009, Shawphy(shawphy.com). All rights reserved.
http://shawphy.com/2009/03/my-own-reset-css.html
Based on YUI http://developer.yahoo.com/yui/reset/ 
and Eric Meyer http://meyerweb.com/eric/tools/css/reset/index.html 
Licensed under the BSD License:
http://creativecommons.org/licenses/BSD/
version: 1.1 | 20090303
*/

body, div, dl, dt, dd, ul, ol, li,
h1, h2, h3, h4, h5, h6, pre, code,
form, fieldset, legend, input, button,
textarea, p, blockquote, th, td {
        margin: 0;
        padding: 0;
}
fieldset, img {
        border: 0;
}
/* remember to define focus styles! */
:focus {
        outline: 0;
}
address, caption, cite, code, dfn,
em, strong, th, var, optgroup {
        font-style: normal;
        font-weight: normal;
}

h1, h2, h3, h4, h5, h6 {
        font-size: 100%;
        font-weight: normal;
}
abbr, acronym {
        border: 0;
        font-variant: normal;
}

input, button, textarea,
select, optgroup, option {
        font-family: inherit;
        font-size: inherit;
        font-style: inherit;
        font-weight: inherit;
}
code, kbd, samp, tt {
        font-size: 100%;
}
/*@purpose To enable resizing for IE */
/*@branch For IE6-Win, IE7-Win */
input, button, textarea, select {
        *font-size: 100%;
}
body {
        line-height: 1.5;
}
ol, ul {
        list-style: none;
}
/* tables still need 'cellspacing="0"' in the markup */
table {
        border-collapse: collapse;
        border-spacing: 0;
}
caption, th {
        text-align: left;
}
sup, sub {
        font-size: 100%;
        vertical-align: baseline;
}
/* remember to highlight anchors and inserts somehow! */
:link, :visited , ins {
        text-decoration: none;
}
blockquote, q {
        quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
        content: '';
        content: none;
}
</style>
<!--#include file="lib/js-google-analytics.asp"-->
</head>

<body>
<%
	sql = "select report_dept,count(report_dept) as num from (SELECT DISTINCT report_dept,report_index,report_empe FROM report where report_xls="&xls_id&" order by report_index) group by report_dept,report_index order by report_index"
	Set rs = conn.execute(sql)
	dept=rs.getrows
	rs.close
	set rs=nothing
	rows=0
	for i=0 to ubound(dept,2)
		rows=rows+dept(1,i)
	next
	half=rows/2
	current_row=0
	left_row=0
	current_dept=0
	sum_all=0
	'response.write(half)
	
%>
<table cellpadding="0" cellspacing="0">
	<tr><th colspan="2" align="center" style="font-size:24px;text-align:center;height:40px" ><%=title%></th></tr>
	<tr><td>
	<table border="1" cellspacing="0" style="width:7.0cm">
<%
	for i=0 to ubound(dept,2)
		if current_row>=half then
			left_row=current_row
			current_dept=i
			exit for
		end if
        
		if dept(1,i)=1 then 
			' sql="select report_dept,sum(report_fee*report_weight) as hj from report where report_xls="&xls_id&" and report_dept='"&dept(0,i)&"' and report_empe='' group by report_dept"
			sql="select report_dept,sum(report_fee*report_weight) as hj from report where report_xls="&xls_id&" and report_dept='"&dept(0,i)&"' group by report_dept"
            ' response.write(sql&"<br />")
			Set rs = conn.execute(sql)
			hj=rs.getrows
			'response.write(ccur(hj(1,0)))
			rs.close
			set rs=nothing
			response.write("<tr style='height:28px'><td colspan='2' align='center'>"&dept(0,i)&"</td><td align='center'>"&FormatNumber(ccur(hj(1,0)),2,-1)&"</td></tr>")
			current_row=current_row+1
			sum_all=sum_all+ccur(hj(1,0))
            
		elseif dept(1,i)>1 then
			sql="select report_empe,sum(report_fee*report_weight) as hj from report where report_xls="&xls_id&" and report_dept='"&dept(0,i)&"' and report_empe<>'' group by report_empe,report_empeindex order by report_empeindex"
			Set rs = conn.execute(sql)
			hj=rs.getrows
            
			for h=0 to ubound(hj,2)
				if h=0 then
					response.write("<tr style='height:28px'><td rowspan='"&dept(1,i)&"' align='center'>"&dept(0,i)&"</td><td align='center'>"&hj(0,h)&"</td><td align='center'>"&FormatNumber(ccur(hj(1,h)),2,-1)&"</td></tr>")
                    
				else
					response.write("<tr style='height:28px'><td align='center'>"&hj(0,h)&"</td><td align='center'>"&FormatNumber(ccur(hj(1,h)),2,-1)&"</td></tr>")
					
				end if
				current_row=current_row+1
				sum_all=sum_all+ccur(hj(1,h))
                
			next
            
			rs.close
			set rs=nothing
            
		end if
        ' if i=8 then
        ' response.write(ubound(dept,2))
        ' response.end
        ' end if

	next
		
%>
	</table>
	</td><td valign="top">
	<table border="1" cellspacing="0" style="width:7.0cm">
<%
	'sum_all=0
	for i=current_dept to ubound(dept,2)
		if dept(1,i)=1 then 
			' sql="select report_dept,sum(report_fee*report_weight) as hj from report where report_xls="&xls_id&" and report_dept='"&dept(0,i)&"' and report_empe='' group by report_dept"
			sql="select report_dept,sum(report_fee*report_weight) as hj from report where report_xls="&xls_id&" and report_dept='"&dept(0,i)&"' group by report_dept"
			Set rs = conn.execute(sql)
			hj=rs.getrows
			'response.write(ccur(hj(1,0)))
			rs.close
			set rs=nothing
			response.write("<tr style='height:28px'><td colspan='2' align='center'>"&dept(0,i)&"</td><td align='center'>"&FormatNumber(ccur(hj(1,0)),2,-1)&"</td></tr>")
			current_row=current_row+1
			sum_all=sum_all+ccur(hj(1,0))
		elseif dept(1,i)>1 then
			sql="select report_empe,sum(report_fee*report_weight) as hj from report where report_xls="&xls_id&" and report_dept='"&dept(0,i)&"' and report_empe<>'' group by report_empe,report_empeindex order by report_empeindex"
			Set rs = conn.execute(sql)
			hj=rs.getrows
			for h=0 to ubound(hj,2)
				if h=0 then
					response.write("<tr style='height:28px'><td rowspan='"&dept(1,i)&"' align='center'>"&dept(0,i)&"</td><td align='center'>"&hj(0,h)&"</td><td align='center'>"&FormatNumber(ccur(hj(1,h)),2,-1)&"</td></tr>")
				else
					response.write("<tr style='height:28px'><td align='center'>"&hj(0,h)&"</td><td align='center'>"&FormatNumber(ccur(hj(1,h)),2,-1)&"</td></tr>")
					
				end if
				current_row=current_row+1
				sum_all=sum_all+ccur(hj(1,h))
			next
			rs.close
			set rs=nothing
		end if
	next
	do while current_row<left_row*2
		response.write("<tr style='height:28px'><td colspan='2' align='center'></td><td align='center'></td></tr>")
		current_row=current_row+1
	loop
	
%>
	</table>
	
	</td></tr><tr style="font-size:20px;height:40px"><td align='center'>合计</td><td align='center'><%=FormatCurrency(ccur(sum_all))%></td></tr></table>		
</body>
</html>
<!--#include file="lib/connclose.asp"-->

